package cn.yanghx.pay.feign;

import cn.yanghx.pay.vo.feign.wechat.app.close.WechatAppPayCloseParams;
import cn.yanghx.pay.vo.feign.wechat.app.prepay.WechatAppPrepayParams;
import cn.yanghx.pay.vo.feign.wechat.app.prepay.WechatAppPrepayResult;
import cn.yanghx.pay.vo.feign.wechat.app.query.WechatAppQueryResult;
import feign.Headers;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

/**
 * 微信app支付feign
 *
 * @author yanghx
 */
@Component
@FeignClient(url = "https://api.mch.weixin.qq.com", name = "wechatAppPayFeign", configuration = WechatAppPayFeignConfig.class)
public interface WechatAppPayFeign {


    /**
     * 发起预支付
     *
     * @param params 预支付参数
     * @return 预支付返回信息
     */
    @PostMapping("/v3/pay/transactions/app")
    WechatAppPrepayResult prepay(WechatAppPrepayParams params);


    /**
     * 微信支付订单号查询.根据微信的订单id
     *
     * @param transactionId 微信支付订单号
     * @param mchId         商户id
     * @return o
     */
    @GetMapping("/v3/pay/transactions/id/{transaction_id}")
    WechatAppQueryResult queryForWechatOrderId(@PathVariable(name = "transaction_id") String transactionId, @RequestParam(name = "mchid") String mchId);


    /**
     * 微信支付订单号查询.根据商户的订单号
     *
     * @param outTradeNo 商户订单号
     * @param mchId      商户id
     * @return o
     */
    @GetMapping("/v3/pay/transactions/out-trade-no/{out_trade_no}")
    WechatAppQueryResult queryForOutTradeNo(@PathVariable(name = "out_trade_no") String outTradeNo, @RequestParam(name = "mchid") String mchId);


    /**
     * 取消订单
     *
     * @param outTradeNo 商户订单号
     * @param params     参数
     * @return o
     */
    @PostMapping("/v3/pay/transactions/out-trade-no/{out_trade_no}/close")
    feign.Response close(@PathVariable(name = "out_trade_no") String outTradeNo, @RequestBody WechatAppPayCloseParams params);


    @GetMapping("/v3/certificates")
    @Headers({
            "Accept: application/json"
    })
    public Object certificates();
}
